﻿using Taype.Trading.BTC.MtGoxAPIClient;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace MtGoxAPIClient_test
{
    
    
    /// <summary>
    ///This is a test class for HelpersTest and is intended
    ///to contain all HelpersTest Unit Tests
    ///</summary>
    [TestClass()]
    public class HelpersTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for Helpers Constructor
        ///</summary>
        [TestMethod()]
        public void HelpersConstructorTest()
        {
            MtGoxHelpers target = new MtGoxHelpers();
            Assert.IsNotNull(target);
        }

        /// <summary>
        ///A test for CalculateBTCPurchaseFee
        ///</summary>
        [TestMethod()]
        public void CalculateBTCPurchaseFeeTest()
        {
            double amount = 1.67215422; // TODO: Initialize to an appropriate value
            double feeRate = 0.46; // TODO: Initialize to an appropriate value
            double expected = 0.00769191; // TODO: Initialize to an appropriate value
            double actual;
            actual = MtGoxHelpers.CalculateBTCPurchaseFee(amount, feeRate);
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for CalculateBTCSaleFee
        ///</summary>
        [TestMethod()]
        public void CalculateBTCSaleFeeTest()
        {
            double amount = 14.40636055; // TODO: Initialize to an appropriate value
            double price = 6.19305; // TODO: Initialize to an appropriate value
            double feeRate = 0.5; // TODO: Initialize to an appropriate value
            double expected = 0.44610; // TODO: Initialize to an appropriate value
            double actual;
            actual = MtGoxHelpers.CalculateBTCSaleFee(amount, price, feeRate);
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for CalculateAccountBalancesAfterTrade
        ///</summary>
        [TestMethod()]
        public void CalculateAccountBalancesAfterTradeTest()
        {
            // test for a purchase (bid)
            double initialBalanceUSD = 10.45335;
            double initialBalanceBTC = 18.37783593;
            double amount = 1.67215422;
            double price = 6.25000;
            double feeRate = 0.46;
            MtGoxTradeType tradeType = MtGoxTradeType.bid;
            double balanceBTC = 0;
            double balanceBTCExpected = 20.04229824;
            double balanceUSD = 0;
            double balanceUSDExpected = 0.00239;
            double feePaid = 0;
            double feePaidExpected = 0.00769191;
            MtGoxHelpers.CalculateAccountBalancesAfterTrade(initialBalanceUSD, initialBalanceBTC, amount, price, feeRate, tradeType, out balanceBTC, out balanceUSD, out feePaid);
            Assert.AreEqual(balanceBTCExpected, balanceBTC);
            Assert.AreEqual(balanceUSDExpected, balanceUSD);
            Assert.AreEqual(feePaidExpected, feePaid);

            // test for a sale (ask)
            initialBalanceUSD = 0.00239;
            initialBalanceBTC = 0.04229824;
            amount = 0.04229824;
            price = 6.31011;
            feeRate = 0.46;
            tradeType = MtGoxTradeType.ask;
            balanceBTC = 0F;
            balanceBTCExpected = 0.0;
            balanceUSD = 0F;
            balanceUSDExpected = 0.26807;
            feePaid = 0F;
            feePaidExpected = 0.00123;
            MtGoxHelpers.CalculateAccountBalancesAfterTrade(initialBalanceUSD, initialBalanceBTC, amount, price, feeRate, tradeType, out balanceBTC, out balanceUSD, out feePaid);
            Assert.AreEqual(balanceBTCExpected, balanceBTC);
            Assert.AreEqual(balanceUSDExpected, balanceUSD);
            Assert.AreEqual(feePaidExpected, feePaid);
        }
    }
}
